home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / Sample Code / Printing Samples / Applications… / QuickDraw GX Aware Sample ƒ / Simple Sample ƒ / printing.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-20  |  3.5 KB  |  159 lines  |  [TEXT/MMCC]

  1. /*********************************************************************
  2.  
  3.     Printing.c
  4.     
  5.     This file contains the printing code for the QuickDraw GX unaware
  6.     sample, "Simple Sample."
  7.     
  8.     Additional info can be found in the related develop #19 article,
  9.     "Adding QuickDraw GX Printing to QuickDraw Applications."
  10.  
  11.     Dave Hersey, Apple Developer Technical Support.
  12.     
  13.     ——————— Edit Trail ———————
  14.     
  15.     coughed up:                                        1/22/94  - dmh
  16.     cleaned up for 2nd draft of develop article:    3/10/94  - dmh
  17.     cleaned up for final:                            4/14/94  - dmh
  18.     
  19. *********************************************************************/
  20.  
  21. #include "Simple Sample.h"
  22.  
  23.  
  24. /************************************************************
  25.   MyPrintDocument - This routine displays the Print dialog,
  26.   and then prints the document.
  27.  
  28. *************************************************************/
  29.  
  30. OSErr MyPrintDocument(MyDocumentPtr whichDocument)
  31. {
  32.     OSErr    err = noErr;
  33.  
  34. /*
  35.     Open the printer driver, and put up the Print dialog.  If
  36.     the user clicks the Print button, print the document.
  37. */
  38.     PrOpen();
  39.  
  40.     PrValidate(whichDocument->documentPrintHdl);
  41.  
  42.     if (PrJobDialog(whichDocument->documentPrintHdl))
  43.         err = MyPrintLoop(whichDocument);
  44.  
  45.     PrClose();
  46.  
  47.     return err;
  48. }
  49.  
  50.  
  51. /************************************************************
  52.   MyPrintLoop - This is our app's print loop.
  53.  
  54. *************************************************************/
  55.  
  56. OSErr MyPrintLoop(MyDocumentPtr whichDocument)
  57. {
  58.     OSErr            err = noErr;
  59.     THPrint            hPrint;
  60.     TPPrPort        printPort;
  61.     TPrStatus        theStatus;
  62.     short            copy, pg, iFstPage, iLstPage, oldCurPage;
  63.  
  64.     hPrint = whichDocument->documentPrintHdl;
  65.     oldCurPage = whichDocument->curPage;
  66.  
  67.     iFstPage = (*hPrint)->prJob.iFstPage;
  68.     if (iFstPage < 1)
  69.         iFstPage = 1;
  70.  
  71.     iLstPage = (*hPrint)->prJob.iLstPage;
  72.     if (iLstPage > whichDocument->numPages)
  73.         iLstPage = whichDocument->numPages;
  74.  
  75.     (*hPrint)->prJob.iFstPage = 1;
  76.     (*hPrint)->prJob.iLstPage = 9999;
  77.  
  78. /*
  79.     Loop for the number of copies we need to make, opening a
  80.     document and a page for each.
  81. */
  82.     for (copy = 1; !err && (copy <= (*hPrint)->prJob.iCopies); copy++)
  83.     {
  84.         printPort = PrOpenDoc(hPrint, nil, nil);
  85.  
  86.         if (!(err = PrError()))
  87.             for (pg = iFstPage; pg <= iLstPage; pg++)
  88.             {
  89.                 PrOpenPage(printPort, nil);
  90.  
  91.                 whichDocument->curPage = pg;
  92.                 MyDrawContents(whichDocument->documentWindow);
  93.         
  94.                 PrClosePage(printPort);
  95.             }
  96.  
  97.         PrCloseDoc(printPort);
  98.     }
  99.  
  100. // When finished printing, call PrPicFile (if necessary).
  101.  
  102.     if (!err) err = PrError();
  103.  
  104.     if (!err && ((*hPrint)->prJob.bJDocLoop == bSpoolLoop))
  105.         PrPicFile(hPrint, nil, nil, nil, &theStatus);
  106.     
  107.     whichDocument->curPage = oldCurPage;
  108.  
  109.     return err;
  110. }
  111.  
  112.  
  113. /************************************************************
  114.   MyDoPageSetup - This routine handles the "Page Setup"
  115.   dialog.
  116.  
  117. *************************************************************/
  118.  
  119. Boolean MyDoPageSetup(MyDocumentPtr whichDocument)
  120. {
  121.     Boolean        result;
  122.  
  123.     PrOpen();
  124.     PrValidate(whichDocument->documentPrintHdl);
  125.     result = PrStlDialog(whichDocument->documentPrintHdl);
  126.     PrClose();
  127.  
  128.     return result;
  129. }
  130.  
  131.  
  132. /************************************************************
  133.   MyRepaginateDoc - This routine handles repagination of our
  134.   document.
  135.  
  136. *************************************************************/
  137.  
  138. void MyRepaginateDoc(MyDocumentPtr whichDocument)
  139. {
  140.     long            pageNum;
  141.     Rect            repaginateRect;
  142.  
  143.     for (pageNum = 1; pageNum <= whichDocument->numPages; pageNum++)
  144.     {
  145.  
  146. //    Repaginate our document using the print record's rPage.
  147.  
  148.         repaginateRect = (*whichDocument->documentPrintHdl)->prInfo.rPage;
  149.  
  150.     /*
  151.         Repaginate the document based on our printable area.
  152.         .
  153.         .
  154.         .
  155.     */
  156.  
  157.     }
  158. }
  159.